package com.iwdnb.gkgz.start;

import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.*;

import gui.ava.html.Html2Image;
import gui.ava.html.renderer.ImageRenderer;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class HtmlToImage {

    protected static void generateOutput() throws Exception {

        //load the webpage into the editor
        //JEditorPane ed = new JEditorPane(new URL("http://www.google.com"));
        JEditorPane ed = new JEditorPane(
            new URL("http://root.com:8001/api/stock/chart/stockEmotionSaveImage?date=2024-12-27"));
        ed.setSize(1000, 800);
        Thread.sleep(10000L);
        //create a new image
        BufferedImage image = new BufferedImage(ed.getWidth(), ed.getHeight(),
            BufferedImage.TYPE_INT_ARGB);

        //paint the editor onto the image
        SwingUtilities.paintComponent(image.createGraphics(),
            ed, new JPanel(), 0, 0, image.getWidth(), image.getHeight());
        //save the image to file
        ImageIO.write((RenderedImage)image, "png", new File("html.png"));
    }

    public static void main(String[] args) {
        try {
            generateOutput();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
